#include <sstream>
#include <iostream>
#include <signal.h>
#include <vector>
#include <opencv2/opencv.hpp>

#include "cudpserverthread.h"

using namespace std;
using namespace cv;

CUdpServerThread *udpThread;
CGloble *mGPara;

//将长焦图转换到短焦图上的对应位置
Mat resizeLongImg(Mat long_img, TransPoint tp, int img_height, int img_width)
{
    Mat img_back = Mat(Size(img_width, img_height), PIC_MAT_TYPE, Scalar(0,0,0));
    int short_height = 80;
    int short_width = 140;
    int start_x = tp.centerX - short_width/2;
    int start_y = tp.centerY - short_height/2;

    Mat imageROI = img_back(Rect(start_x, start_y, short_width, short_height));
    Mat short_img;
    resize(long_img, short_img, Size(short_width, short_height), INTER_CUBIC);
    short_img.copyTo(imageROI);
    return img_back;
}

int main(int argc, char **argv)
{
    // 启动摄像头接收线程
    udpThread = new CUdpServerThread;
    udpThread->Start();

    // 主线程操作
    mGPara = CGloble::getInstance();
    pair<SUdpDataHead,SUdpData> write_pair;
    SUdpDataHead write_count;
    SUdpData write_mat;
    Mat src_img;
    while (true)
    {
        mGPara->m_semUdp.Wait();
        if(!mGPara->m_queWriteUdpData.empty())
        {
            mGPara->popQue(write_pair);
            write_count = write_pair.first;
            write_mat = write_pair.second;
            src_img = write_mat.src;
            imshow("display",src_img);
            waitKey(10);
        }
    }
    return 0;
}